using UnityEngine;

public class EnemyState_LangJianKe_追击 : EnemyStateBase_LangJianKe
{
	private Vector2 _targetPos;

	private Vector2 _StartPos;

	private float _Speed = 2f;

	private Vector2 _DirSpeed;

	private float _离开视野时间;

	public override void OnEnter()
	{
		_离开视野时间 = 0f;
		_Mono._Ani.Play("持刀移动");
		_StartPos = _Mono.transform.position;
		Vector2 vector = _Mono._Tsf_玩家.position;
		_targetPos = vector + new Vector2((float)((vector.x < _StartPos.x) ? 1 : (-1)) * Random.Range(1f, 3f), Random.Range(-0.5f, 0.5f));
		_Mono.transform.localScale = new Vector3((vector.x > _StartPos.x) ? 1 : (-1), 1f, 1f);
		_DirSpeed = (_targetPos - _StartPos).normalized * _Speed;
		_Mono._Tsf_移动目标.transform.position = _targetPos;
		RaycastHit2D[] array = Physics2D.RaycastAll(_StartPos, (_targetPos - _StartPos).normalized, Vector2.Distance(_targetPos, _StartPos));
		bool flag = false;
		if (array.Length != 0)
		{
			RaycastHit2D[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit2D raycastHit2D = array2[i];
				if (raycastHit2D.transform.parent != null && raycastHit2D.transform.parent.name == "碰撞")
				{
					flag = true;
					break;
				}
			}
		}
		if (flag)
		{
			_Mono._连续移动撞墙次数++;
		}
		else
		{
			_Mono._连续移动撞墙次数 = 0f;
		}
		if (_Mono._Is视野范围内)
		{
			_Timer = Random.Range(1f, 1.5f);
		}
		else
		{
			_Timer = Random.Range(2f, 2.5f);
		}
	}

	public override void OnExit()
	{
	}

	public override void OnUpdate()
	{
		_Timer -= Time.deltaTime * _Speed;
		_Mono._Rb2D.velocity = Vector2.Lerp(_Mono._Rb2D.velocity, _DirSpeed, Time.deltaTime * 10.9f);
		if (!_Mono._Is视野范围内)
		{
			_离开视野时间 += Time.deltaTime;
			if (_离开视野时间 >= 5f)
			{
				_Mono._Is追击中 = false;
				_Mono._Rb2D.velocity = Vector2.zero;
				_Mono.ChangeState(StateType_Enemy_XiaoGuai.站立);
			}
		}
		else
		{
			_离开视野时间 = 0f;
		}
		if (_Timer < 0f)
		{
			if (_Mono._Is视野范围内 && Random.value < 0.75f)
			{
				_Mono.ChangeState(StateType_Enemy_XiaoGuai.攻击);
			}
			else
			{
				_Mono.ChangeState(StateType_Enemy_XiaoGuai.追击);
			}
		}
	}
}
